package com.thinkgem.jeesite.modules.api.web;

import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.sys.entity.firm.Firm;
import com.thinkgem.jeesite.modules.sys.entity.firm.tonji;
import com.thinkgem.jeesite.modules.sys.service.firm.FirmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "/api/firm")
public class FrimAPIController extends BaseController {

    @Autowired
    private FirmService firmService;
    @ResponseBody
    @RequestMapping(value = "/getMemberMap", method = RequestMethod.GET)
    public ModelAndView getMemberMap(){
        ModelAndView mv = new ModelAndView();
        List<tonji> tj = firmService.ztonji();
        mv.addObject("tj",tj);
        mv.setViewName("/modules/wx/wxxinxi");
        return mv;
    }

    @ResponseBody
    @RequestMapping(value = "/getMmap", method = RequestMethod.GET)
    public ModelAndView getMmap(String ids){
        ModelAndView mv = new ModelAndView();
        mv.addObject("ids",ids);
        mv.setViewName("/modules/wx/wxmembermap");
        return mv;
    }

    @ResponseBody
    @RequestMapping(value = "/tonji")
    public Object tonji(String officeId){
        List<Map<String,Object>> list = firmService.tonJi(officeId);
        Map<String,Object> ma1 = new HashMap<String,Object>();
        ma1.put("1","0");ma1.put("2","0");ma1.put("3","0");ma1.put("4","0");ma1.put("5","0");ma1.put("6","0");ma1.put("7","0");
        if(list.size()>0 || list != null){
            for (Map<String,Object> item:list){
                ma1.put(item.get("zt").toString(), item.get("num").toString());
            }
        }
        return ma1;
    }

    @ResponseBody
    @RequestMapping(value = "/getCheck", method = RequestMethod.GET)
    public ModelAndView getCheck(){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("/modules/wx/chechMember");
        return mv;
    }

    @ResponseBody
    @RequestMapping(value = "/getStatic", method = RequestMethod.GET)
    public ModelAndView getStatic(String memberName){
        ModelAndView mv = new ModelAndView();
        List<Firm> ids = firmService.getStatic(memberName);
        if(ids.size()==1){
            mv.addObject("ids",ids );
            mv.setViewName("/modules/wx/memberStatic");
        }
        if(ids .size() == 0){
            mv.setViewName("/modules/wx/memberStatic0");
        }
        if(ids .size() >= 2){
            mv.setViewName("/modules/wx/memberStaticN");
        }

        return mv;
    }

}
